package dataManage.tools;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.gjs.tools.JDBC.JDBCTools;

public class Sequence {
	public static int queryCurrVal(String seqName, Connection con) {
		String sql = "select " + seqName + ".currval from dual";
		return queryVal(sql);
		
	}
	public static int queryNextVal(String seqName) {
		String sql = "select " + seqName + ".nextval from dual";
		return queryVal(sql);
	}
	private static int queryVal(String sql) {
		Statement state = null;
		ResultSet result = null;
		Connection con = JDBCTools.getConnection();
		try {
			try {
				state = con.createStatement();
				result = state.executeQuery(sql);
				if (result.next()) {
					return result.getInt(1);
				}
			} finally {
				JDBCTools.releaseDB(result, state, con);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}
}
